<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <div th:include="base-libs :: base-libs" />
    <title>医联体服务台账—新增</title>

    <script th:src="@{/tbxt/js/easyui_editModel.js}"></script>
    <script th:src="@{/tbxt/js/TzUtils.js}"></script>

    <style>
        .spanBtn{
            font-weight: bold;
            color: blue;
            cursor:pointer;
        }
    </style>
    <script>
        var $addTb , yltAry;

        $(function(){
            $addTb = $("#addTb");
            $(this).registerManagerPage({cacheTables:["TB_ZY_YLTLX"],callback:initView});
            //initView();
            //initData();
        })

        function initView(){
            yltAry = StoreCache.getCache("TB_ZY_YLTLX").data;
            /* 模板表格 */
            $("#modelTb").datagrid({
                fitColumns: true,
                fit:true,
                scrollbarSize:10,
                rownumbers: true,
                columns : [[
                    {field : "FWSJ",title : "2017-07-02",width:100,align:'center'},
                    {field : "FWMC",title : "坐诊",width:80,align:'center'},
                    {field : "FWNR",title : "为基层医疗机构提供主任及以上医师的坐诊服务",width:200,align:'left'},
                    {field : "TGFWJG",title : "南昌市第一医院",width:100,align:'left'},
                    {field : "JSFWJG",title : "西湖区社区卫生",width:80,align:'center'},
                    {field : "YLTLX",title : "医疗联合体",width:80,align:'center'},
                    {field : "cz",title : "",width:80,align:'center'}
                ]]
            });

            /** 添加表格  */
            $addTb.datagrid({
                striped : true,
                clickToSelect: true,
                fitColumns: true,
                singleSelect: true,
                fit:true,
                scrollbarSize:10,
                rownumbers: true,
                columns : [[
                    {field : "FWSJ",title : "服务时间",width:100,align:'center',
                        editor:{
                            type: "laydate",
                            options:{
                                label: '服务时间',
                                validateProxy:'notNull D10',
                            }
                        }
                    },
                    {field : "FWMC",title : "服务名称",width:80,align:'center',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '服务人员',
                                length:32,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "FWNR",title : "服务内容",width:200,align:'left',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '服务项名称',
                                length:128,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "TGFWJG",title : "提供服务机构",width:100,align:'left',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '服务项内容',
                                length:64,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "JSFWJG",title : "接收服务机构",width:80,align:'center',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '服务对象',
                                length:64,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "YLTLX",title : "医联体类型",width:80,align:'center',
                        formatter:function(value,row){
                            $.each(yltAry, function(i, item){
                                if(item.XMMC==value){
                                    row.YLTLX = item.XMDM;
                                    return false;
                                }
                                if(item.XMDM==value){
                                    value = item.XMMC;
                                    return false;
                                }
                            })
                            return value;
                        },
                        editor:{
                            type: "quickSelectValidate",
                            options:{
                                valueField:'XMDM',
                                textField:'XMMC',
                                data: yltAry,
                                label: '医联体类型',
                                validateProxy:'notNull',
                            }
                        }
                    },
                    {field : "cz",title : "操作",width:80,align:'center', formatter:function(value,row,index){
                        return TzUtils.formatZcBtn(index);
                    }}
                ]],
                onClickRow : function(rowIndex, row){
                    var editRowNum = $(this).data("editRowNum");
                    if(!StringUtils.isEmpty(editRowNum) && rowIndex != editRowNum){
                        //不做数据验证（避免和添加按钮中的验证重复）
                        $(this).datagrid('endEdit', editRowNum).datagrid('beginEdit', rowIndex)
                            .data("editRowNum",rowIndex);
                    }
                },
            });

            /** 添加一行  */
            $("body").on("click",".btnTj",function(){
                TzUtils.addRow();
            })

            /** 删除一行  */
            $("body").on("click",".btnSc",function(){
                TzUtils.deleteRow();
            })

            /** 提交 */
            $("#btnTj").click(function () {
                TzUtils.save(contextRoot + "ylttz/save");
            })

            /** 返回 */
            $("#btnFh").click(function () {
                $.QuickUrlUtils.redirectUrl("index.html");
            })
            
            /** 导入 */
            $("#btnDr").click(function () {
                TzUtils.openImpotView(contextRoot + 'ylttz/import.html');
            })

            /** 下载模板 */
            $("#btnXzmb").click(function () {
                $("#formXzmb").submit();
            })

            //改变样例表格样式
            TzUtils.format_modelTbStyle();
            TzUtils.addRow(); //默认添加一行
        }


    </script>
</head>
<body class="easyui-layout" fit="true">
    <div region="north" style="height:80px;border:0;overflow: hidden">
        <h3 style="font-size:14px;padding: 15px 0px 3px 15px;">
            <span id="haha"></span>
            <span style="font-weight: bold;letter-spacing:0.5px">请按以下格式新增医联体服务记录：</span>
            <button id="btnXzmb" class="btn btn-info" type="button" style="float:right;margin-right:35px;margin-left:0px;position:relative;top:-8px">下载模板</button>
            <button id="btnDr" class="btn btn-info" type="button" style="float:right;margin-right:8px;position:relative;top:-8px">导入</button>
        </h3>
        <table id="modelTb"></table>
    </div>
    <div region="center" border="false">
        <table id="addTb"></table>
    </div>
    <div region="south" style="height:40px;line-height:40px;border:0;border-top:1px solid #ddd;text-align: center;overflow: hidden">
        <button id="btnTj" class="btn btn-info" type="button">提交</button>
        <button id="btnFh" class="btn btn-info" type="button">返回</button>
    </div>

    <form id="formXzmb" action="downExcelModel" method="post" enctype="multipart/form-data"></form>
    <form id="formDr" action="parseExcalData" method="post" enctype="multipart/form-data" style="opacity: 0;display: none">
        <input id="fileField" type="file" name="fileField"  />
    </form>

</body>
</html>